<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>

		<link rel="stylesheet" type="text/css" href="assets/css/layui.css" />
		<script src="assets/layui.js" type="text/javascript" charset="utf-8"></script>

		<link rel="stylesheet" type="text/css" href="js/bootstarp-3.3.7/css/bootstrap.min.css" />
		<script src="js/jquery/jquery-3.2.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/bootstarp-3.3.7/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>

		<link rel="stylesheet" type="text/css" href="js/bootstarp-table-1.11.1/bootstrap-table.min.css" />
		<script src="js/bootstarp-table-1.11.1/bootstrap-table.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/bootstarp-table-1.11.1/bootstrap-table-zh-CN.min.js" type="text/javascript" charset="utf-8"></script>

	</head>

	<script>
		$(function() { //, headers: { 'x-requested-with': 'XMLHttpRequest' }
			$.ajaxSetup({
				crossDomain: true,
				xhrFields: {
					withCredentials: true
				}
			});
		});
	</script>

	<script type="text/javascript">
		layui.use(['element', 'form', 'layer'], function() {
			var $ = layui.jquery,
				layer = layui.layer,
				form = layui.form,
				element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
		})

		$(function() {

			$("#btn").click(function() {

				$("#ghlb").bootstrapTable('refresh')
			})
            //未就诊
			$("#ghlb").bootstrapTable({
				url: "http://localhost:8091/jzlb/queryPatient",
				pagination: true,
				pageSize: 5,
				queryParams: queryParams,
				columns: [{
						title: '序号',
						align: 'center',
						valign: 'middle',
						formatter: function(value,row, index) {
							return index + 1;
						}
					}, {
						field: 'name',
						title: '患者姓名',
						align: 'center',
						valign: 'middle',
					}, {
						field: 'sex',
						title: '性别',
						align: 'center',
						valign: 'middle',
					}, {
						field: 'birthday',
						title: '年龄',
						align: 'center',
						valign: 'middle',
					}, {
						field: 'mobile',
						title: '电话',
						align: 'center',
						valign: 'middle',
					}, {
						field: 'create_time',
						title: '挂号时间',
						align: 'center',
						valign: 'middle',
					}, {
						field: 'registration_status',
						title: '挂号状态',
						align: 'center',
						valign: 'middle',
						formatter:function(value,data){
		                       if(value=="1"){
			                      return "未就诊" ;
		                       }
		              } 
					},{
						title: '操作',
						align: 'center',
						valign: 'middle',
						formatter: function(value, row, index) {
							var w = '<button onclick="jiuzhen(' + row.patient_id + ',' + row.registration_id + ')" class="btn btn-success">就诊</button> '
							w += '<button onclick="tuihao(3,' + row.registration_id + ','+ row.patient_id +')" class="btn btn-warning">退号</button> '
							w += '<button onclick="zuofei(4,' + row.registration_id + ','+ row.patient_id +')" class="btn btn-danger">作废</button> '

							return w;
						}
					}
				]
			})
			//参数
			function queryParams(Params) {
			return {
				'name': $("#name").val()
			}
		}

			$("#btn2").click(function() {

				$("#hzk").bootstrapTable('refresh')
			})
            //已就诊
			$("#hzk").bootstrapTable({
				url: "http://localhost:8091/jzlb/findAllStatus",
				pagination: true,
				pageSize: 5,
				queryParams: queryParams2,
				columns: [{
					title: '序号',
					align: 'center',
					valign: 'middle',
					formatter: function(value, row, index) {
						return index + 1;
					}
				}, {
					field: 'name',
					title: '患者姓名',
					align: 'center',
					valign: 'middle',
				}, {
					field: 'sex',
					title: '性别',
					align: 'center',
					valign: 'middle',
					formatter:function(value,data){
		                       if(value=="1"){
			                      return "男" ;
		                       }if(value=="2"){
			                      return "女" ;
		                }
		              } 
				}, {
					field: 'birthday',
					title: '年龄',
					align: 'center',
					valign: 'middle',
				}, {
					field: 'mobile',
					title: '电话',
					align: 'center',
					valign: 'middle',
				}, {
					field: 'addtime',
					title: '就诊时间',
					align: 'center',
					valign: 'middle',
				}, {
					field: 'type_id',
					title: '挂号类型',
					align: 'center',
					valign: 'middle',
					formatter:function(value,data){
		                       if(value=="0"){
			                      return "初诊" ;
		                       }if(value=="1"){
			                      return "急诊" ;
		                       }if(value=="2"){
			                      return "复诊" ;
		                }
		              } 
				}, {
					field: 'status',
					title: '支付状态',
					align: 'center',
					valign: 'middle',
					formatter:function(value,data){
		                       if(value=="0"){
			                      return "未支付" ;
		                       }if(value=="1"){
			                      return "已支付" ;
		                       }if(value=="2"){
			                      return "确认收款" ;
		                       }if(value=="3"){
			                      return "申请退款" ;
		                       }if(value=="4"){
			                      return "已退款" ;
		                       }if(value=="5"){
			                      return "部分支付" ;
		                       }else{
		                       	  return "完成交易";
		                       }
		              } 
				}]

			})

		})
		//带参数
		function queryParams2(Params) {
			return {
				'names': $("#patientname").val()

			}
		}

        //退号
		function tuihao(status,id,patient_id) {
			layer.confirm('一旦退号您需要重新挂号,确定退号吗？', function(index) {
				$.ajax({
					type: "post",
					url: "http://localhost:8091/jzlb/updateRegStatus",
					data: "status="+status+"&registration_id="+id+"&patient_id="+patient_id,
					success: function(data) {
						if(data.msg=='true'){
							layer.msg('退号成功', {
							icon: 1
						});
						$("#ghlb").bootstrapTable('refresh');
						}else{
							layer.msg('退号失败', {
							icon: 1
						});
						}
						
					}
				});
			});
		}
        //作废
		function zuofei(status, id,patient_id) {
			layer.confirm('确认要作废吗？一旦作废不可就诊', function(index) {
				$.ajax({
					type: "get",
					url: "http://localhost:8091/jzlb/updateRegStatus",
					data: "status=" + status + "&registration_id=" + id+"&patient_id="+patient_id,
					success: function(data) {
						if(data.msg=='true'){
							layer.msg('作废成功', {
							icon: 1
						});
						$("#ghlb").bootstrapTable('refresh');
						}else{
							layer.msg('作废失败', {
							icon: 1
						});
						}
					}
				});
			});
		}
        //就诊
		function jiuzhen(id, regid) {
			window.location = "xkjz.html?id=" + id + "&registrationId=" + regid;

		}

		

		
	</script>

	<body>
		<div class="layui-tab layui-tab-card">
			<ul class="layui-tab-title">
				<li class="layui-this" style="width: 50%;">未就诊</li>
				<li style="width: 50%;">已就诊</li>
			</ul>
			<div class="layui-tab-content" style="height: 500px;">
				<div class="layui-tab-item layui-show" align="center">
					<form class="form-inline">
						<label for="exampleInputName2">患者姓名：</label>
						<input type="text" class="form-control" name="name" id="name"  placeholder="请输入姓名" />
						<button type="button" class="btn btn-primary glyphicon glyphicon-search" id="btn"></button>
					</form>
					<br />
					<div>
						<table id="ghlb" class="table"></table>
					</div>
				</div>

				<div class="layui-tab-item" align="center">
					<form class="form-inline">
						<label for="exampleInputName2">患者姓名：</label>
						<input type="text" class="form-control"  id="patientname"  placeholder="请输入姓名" />
						<button type="button" class="btn btn-primary glyphicon glyphicon-search" id="btn2"></button>

					</form>
					<br />
					<div>
						<table id="hzk"></table>
					</div>

				</div>

			</div>
		</div>

	</body>

</html>